<?php

namespace app\common\service\shop\shopee;

/**
 * Goods
 * @package app\common\service\shopee
 * @Description shopee跨境平台接口服务-商品相关接口
 * @author xuli
 * @date 2024-10-23 09:11
 */
class Goods extends BaseApi
{

    /**
     * 分类列表
     * @return void
     */
    public function categoryList()
    {
        $data = [];
        $this->shopApi('get_category', '', $data);

        $return_data = [
            "error" => "",
            "message" => "",
            "warning" => "",
            "request_id" => "aaaaaaa",
            "response" => [
                "category_list" => [
                    [
                        "category_id" => 123,
                        "parent_category_id" => 456,
                        "original_category_name" => "aaa",
                        "display_category_name" => "bbb",
                        "has_children" => false
                    ]
                ]
            ]
        ];
    }

    /**
     * 获取属性
     * @return void
     */
    public function getAttributes()
    {
        $data = [
            'category_id' => 1
        ];
        $this->shopApi('get_category', '', $data);

        $return_data = [
            "error" => "-",
            "message" => "-",
            "warning" => "-",
            "request_id" => "-",
            "response" => [
                "attribute_list" => [[
                    "attribute_id" => 0,
                    "original_attribute_name" => "-",
                    "display_attribute_name" => "-",
                    "is_mandatory" => true,
                    "input_validation_type" => "-",
                    "format_type" => "-",
                    "date_format_type" => "-",
                    "input_type" => "-",
                    "attribute_unit" => ["-"],
                    "attribute_value_list" => [[
                        "value_id" => 0,
                        "original_value_name" => "-",
                        "display_value_name" => "-",
                        "value_unit" => "-",
                        "parent_attribute_list" => [[
                            "parent_attribute_id" => 0,
                            "parent_value_id" => 0
                        ]],
                        "parent_brand_list" => [[
                            "parent_brand_id" => 0
                        ]]
                    ]]
                ]]
            ]
        ];
    }

    /**
     * 获取品牌
     * @return void
     */
    public function getBrandList()
    {
        $data = [
            'category_id' => 1
        ];
        $this->shopApi('get_category', '', $data);

        $return_data = [
            "error" => "",
            "message" => "",
            "warning" => "",
            "request_id" => "6faac36a4a3242aabad2941e3acd7297",
            "response" => [
                "brand_list" => [[
                    "brand_id" => 2500139861,
                    "original_brand_name" => "nike",
                    "display_brand_name" => "nike"
                ]],
                "has_next_page" => true,
                "next_offset" => 10,
                "is_mandatory" => false,
                "input_type" => "TEXT_FILED"
            ]
        ];
    }

    /**
     * 添加商品
     * @return void
     */
    public function addGoods()
    {
        $data = [
            "attribute_list" => [
                [
                    "attribute_id" => 4990,
                    "attribute_value_list" => [
                        [
                            "original_value_name" => "Brand",
                            "value_id" => 32142,
                            "value_unit" => " kg"
                        ]
                    ]
                ]
            ],
            "brand" => [
                "brand_id" => 0,
                "original_brand_name" => "nike"
            ],
            "category_id" => 14695,
            "complaint_policy" => [
                "additional_information" => "-",
                "complaint_address_id" => 0,
                "exclude_entrepreneur_warranty" => true,
                "warranty_time" => "-"
            ],
            "condition" => "NEW",
            "description" => "item description test",
            "description_info" => [
                "extended_description" => [
                    "field_list" => [
                        [
                            "field_type" => "-",
                            "image_info" => [
                                "image_id" => "-"
                            ],
                            "text" => "-"
                        ]
                    ]
                ]
            ],
            "description_type" => "-",
            "dimension" => [
                "package_height" => 11,
                "package_length" => 11,
                "package_width" => 11
            ],
            "image" => [
                "image_id_list" => ["-"]
            ],
            "item_dangerous" => 0,
            "item_name" => "Item Name Example",
            "item_sku" => "-",
            "item_status" => "UNLIST",
            "logistic_info" => [
                [
                    "enabled" => true,
                    "is_free" => true,
                    "logistic_id" => 80101,
                    "shipping_fee" => 23.12,
                    "size_id" => 0
                ]
            ],
            "normal_stock" => 33,
            "original_price" => 123.3,
            "pre_order" => [
                "days_to_ship" => 3,
                "is_pre_order" => true
            ],
            "seller_stock" => [
                [
                    "location_id" => "-",
                    "stock" => 0
                ]
            ],
            "tax_info" => [
                "cest" => "-",
                "csosn" => "-",
                "diff_state_cfop" => "-",
                "hs_code" => "-",
                "invoice_option" => "-",
                "measure_unit" => "-",
                "ncm" => "-",
                "origin" => "-",
                "same_state_cfop" => "-",
                "tax_code" => "-",
                "vat_rate" => "-"
            ],
            "video_upload_id" => [
                "sg_f4bde9bc-ff3c-485e-a6dd-3161dab4b942_000000"
            ],
            "weight" => 1.1,
            "wholesale" => [
                [
                    "max_count" => 100,
                    "min_count" => 1,
                    "unit_price" => 28.3
                ]
            ]
        ];
        $this->shopApi('add_goods', '', $data);
    }

    /**
     * 更新商品
     * @return void
     */
    public function updateGoods()
    {
        $data = [
            "attribute_list" => [
                [
                    "attribute_id" => 5357,
                    "attribute_value_list" => [
                        [
                            "original_value_name" => "Red",
                            "value_id" => 38173,
                            "value_unit" => "kg"
                        ]
                    ]
                ]
            ],
            "brand" => [
                "brand_id" => 0,
                "original_brand_name" => "nike"
            ],
            "category_id" => 34106,
            "complaint_policy" => [
                "additional_information" => "-",
                "complaint_address_id" => 0,
                "exclude_entrepreneur_warranty" => true,
                "warranty_time" => "-"
            ],
            "condition" => "USED",
            "description" => "Hello product product WlQPdMV4SlVoG7QD1v0fEecNoCVEBNx6",
            "description_info" => [
                "extended_description" => [
                    "field_list" => [
                        [
                            "field_type" => "-",
                            "image_info" => [
                                "image_id" => "-"
                            ],
                            "text" => "-"
                        ]
                    ]
                ]
            ],
            "description_type" => "-",
            "dimension" => [
                "package_height" => 13,
                "package_length" => 12,
                "package_width" => 14
            ],
            "image" => [
                "image_id_list" => [
                    []
                ]
            ],
            "item_dangerous" => 0,
            "item_id" => 2800143058,
            "item_name" => "Hello Pgkk50jdNgEnlWvX",
            "item_sku" => "abc",
            "item_status" => "UNLIST",
            "logistic_info" => [
                [
                    "enabled" => true,
                    "is_free" => true,
                    "logistic_id" => 10007,
                    "shipping_fee" => 9,
                    "size_id" => 1
                ]
            ],
            "pre_order" => [
                "days_to_ship" => 7,
                "is_pre_order" => true
            ],
            "tax_info" => [
                "cest" => "-",
                "csosn" => "-",
                "diff_state_cfop" => "-",
                "hs_code" => "-",
                "invoice_option" => "-",
                "measure_unit" => "-",
                "ncm" => "-",
                "origin" => "-",
                "same_state_cfop" => "-",
                "tax_code" => "-",
                "vat_rate" => "-"
            ],
            "video_upload_id" => [
                []
            ],
            "weight" => 0.9,
            "wholesale" => [
                [
                    "max_count" => 10,
                    "min_count" => 0,
                    "unit_price" => 9.9
                ]
            ]
        ];
        $this->shopApi('update_goods', '', $data);

        $return_data = [
            "message" => "-",
            "warning" => "-",
            "request_id" => "98eae35efff24dd0974c21a847127184",
            "response" => [
                "description" => "description",
                "weight" => 1,
                "pre_order" => [
                    "days_to_ship" => 1,
                    "is_pre_order" => true
		        ],
		        "item_name" => "Hello Product",
		        "images" => [
                    "image_id_list" => [
                        "-"
                    ],
			        "image_url_list" => [
                        "-"
                    ]
		        ],
                "item_status" => "NORMAL",
                "price_info" =>[
                        "current_price" => 148.02,
                    "original_price" => 148.02
                ],
                "logistic_info" => [
                    [
                        "size_id" => 0,
                        "shipping_fee" => 0.1,
                        "enabled" => true,
                        "logistic_id" => 88014,
                        "is_free" => true
                    ]
                ],
                "stock_info" => [
                        "normal_stock" => 33,
                    "stock_type" => 2,
                    "current_stock" => 33
                ],
                "item_id" => 3000142341,
                "attributes" => [
                    [
                        "attribute_id" => 4990,
                        "attribute_value_list" => [
                            [
                                "original_value_name" => "Samsung ID",
                                "value_id" => 32142,
                                "value_unit" => "kg"
                            ]
                        ]
                    ]
                ],
                "category_id" => 14695,
                "dimension" => [
                        "package_width" => 11,
                    "package_length" => 11,
                    "package_height" => 11
                ],
                "condition" => "NEW",
                "video_info" => [
                    [
                        "video_url" => "https://cvf.shopee.sg/file/c67b847c954fd710e0d35ef1e22378d1",
                        "thumbnail_url" => "https://cf.shopee.sg/file/6fc53c203151635da72151cfbad03cdf",
                        "duration" => 15
                    ]
                ],
                "wholesale" => [
                    [
                        "min_count" => 1,
                        "max_count" => 100,
                        "unit_price" => 13.3
                    ]
                ],
                "brand" => [
                    "brand_id" => 0,
                    "original_brand_name" => "nike"
                ],
                "item_dangerous" => 0,
                "description_info" => [
                        "extended_description" => [
                            "field_list" => [
                                [
                                "field_type" => "-",
                                "text" => "-",
                                "image_info" => [
                                    "image_id" => "-"
                                ]
                            ]
                        ]
                    ]
                ],
                "description_type" => "-",
                "complaint_policy" => [
                        "warranty_time" => "ONE_YEAR",
                    "exclude_entrepreneur_warranty" => true,
                    "complaint_address_id" => 0,
                    "additional_information" => "-"
                ],
                "seller_stock" => [
                    [
                        "location_id" => "-",
                        "stock" => 0
                    ]
                ]
            ],
            "error" => "-"
        ];
    }

    /**
     * 上传图片
     * @return void
     */
    public function uploadImage()
    {
        $data = [
            "image" => new \CURLFile('/path/to/image.jpg')
        ];
        $this->shopApi('upload_image', '', $data);

        $return_data = [
            "error" => "-",
            "message" => "-",
            "warning" => "-",
            "request_id" => "-",
            "response" => [
                "image_info" => [
                    "image_id" => "-",
                    "image_url_list" => [
                        [
                            "image_url_region" => "-",
                            "image_url" => "-"
                        ]
                    ]
                ],
                "image_info_list" => [
                    [
                        "id" => 0,
                        "error" => "-",
                        "message" => "-",
                        "image_info" => [
                        "image_id" => "-",
                            "image_url_list" => [
                                [
                                    "image_url_region" => "-",
                                    "image_url" => "-"
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ];
    }

    /**
     * 搜索商品
     * @return void
     */
    public function searchGoods()
    {
        $data = [
            "offset" => "",
            "page_size" => "",
            "item_name" => "",
            "attribute_status" => "",
            "item_sku" => "",
            "item_status" => "",
            "deboost_only" => "",
        ];
        $this->shopApi('search_goods', '', $data);

        $return_data = [
            "error" =>  "",
            "message" =>  "",
            "warning" =>  "",
            "request_id" =>  "6faac36a4a3242aabad2941e3acd7297",
            "response" =>  [
                "item_id_list" =>  [
                    653211,564331
                ],
                "next_offset" => "xsszxjcdeahx",
                "total_count" => 100,
            ]
        ];
    }

    /**
     * 获取商品基础信息
     * @return void
     */
    public function getGoodsInfo()
    {
        $data = [
            "item_id_list" => [34001,34002],
        ];

        $this->shopApi('goods_info', '', $data);

        $return_data = [
            "error" => "-",
            "message" => "-",
            "warning" => "-",
            "request_id" => "7b9da0c6926642199c33ee9dd3a266f5",
            "response" => [
                "item_list" => [
                    [
                        "item_id" => 34002,
                        "category_id" => 14646,
                        "item_name" => "seller discount",
                        "description" => "first product 001first product",
                        "item_sku" => "-",
                        "create_time" => 1600572637,
                        "update_time" => 1600572640,
                        "attribute_list" => [
                            [
                                "attribute_id" => 4811,
                                "original_attribute_name" => "Brand: L2 Default [14644]",
                                "is_mandatory" => true,
                                "attribute_value_list" => [
                                    [
                                        "value_id" => 0,
                                        "original_value_name" => "Default",
                                        "value_unit" => "g"
                                    ]
                                ]
                            ]
                        ],
                        "price_info" => [
                            [
                                "currency" => "SGD",
                                "original_price" => 122.02,
                                "current_price" => 122.02,
                                "inflated_price_of_original_price" => 222.02,
                                "inflated_price_of_current_price" => 111.02,
                                "sip_item_price" => 100.02,
                                "sip_item_price_source" => "auto"
                            ]
                        ],
                        "image" => [
                        "image_url_list" => [
                            "-"
                        ],
                            "image_id_list" => [
                            "-"
                        ]
                        ],
                        "weight" => "10.02",
                        "dimension" => [
                        "package_length" => 11,
                            "package_width" => 12,
                            "package_height" => 13
                        ],
                        "logistic_info" => [
                            [
                                "logistic_id" => 80012,
                                "logistic_name" => "-",
                                "enabled" => true,
                                "shipping_fee" => 5.02,
                                "size_id" => 0,
                                "is_free" => true,
                                "estimated_shipping_fee" => 4.02
                            ]
                        ],
                        "pre_order" => [
                        "is_pre_order" => true,
                            "days_to_ship" => 3
                        ],
                        "wholesales" => [
                            [
                                "min_count" => 1,
                                "max_count" => 2,
                                "unit_price" => 4.02,
                                "inflated_price_of_unit_price" => 5.02
                            ]
                        ],
                        "condition" => "NEW/USED",
                        "size_chart" => "-",
                        "item_status" => "NORMAL",
                        "deboost" => "false",
                        "has_model" => true,
                        "promotion_id" => 13123,
                        "video_info" => [
                            [
                                "video_url" => "-",
                                "thumbnail_url" => "-",
                                "duration" => 0
                            ]
                        ],
                        "brand" => [
                        "brand_id" => 123,
                            "original_brand_name" => "nike"
                        ],
                        "item_dangerous" => 0,
                        "complaint_policy" => [
                        "warranty_time" => " ONE_YEAR",
                            "exclude_entrepreneur_warranty" => true,
                            "complaint_address_id" => 0,
                            "additional_information" => "-"
                        ],
                        "tax_info" => [
                        "ncm" => "-",
                            "diff_state_cfop" => "-",
                            "csosn" => "-",
                            "origin" => "-",
                            "cest" => "-",
                            "measure_unit" => "-",
                            "invoice_option" => "-",
                            "vat_rate" => "-",
                            "hs_code" => "-",
                            "tax_code" => "-"
                        ],
                        "description_info" => [
                            "extended_description" => [
                                "field_list" => [
                                    [
                                        "field_type" => "-",
                                        "text" => "-",
                                        "image_info" => [
                                        "image_id" => "-",
                                            "image_url" => "-"
                                        ]
                                    ]
                                ]
                            ]
                        ],
                        "description_type" => "-",
                        "stock_info_v2" => [
                        "summary_info" => [
                            "total_reserved_stock" => 100,
                                "total_available_stock" => 100
                            ],
                            "seller_stock" => [
                                [
                                    "location_id" => "-",
                                    "stock" => 10
                                ]
                            ],
                            "shopee_stock" => [
                                [
                                    "location_id" => "-",
                                    "stock" => 0
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ];
    }

    /**
     * 更新价格
     * @return void
     */
    public function updatePrice()
    {
        $data = [
        "item_id" => 1000,
        "price_list" => [[
            "model_id" => 3456,
            "original_price" => 11.11
            ]]
        ];

        $this->shopApi('update_price', '', $data);

        $return_data = [
            "error" => "",
            "message" => "",
            "warning" => "",
            "request_id" => "aaaaaaa",
            "response" => [
                "failure_list" => [[
                    "model_id" => 3456,
                    "failed_reason" => "fail"
                ]],
                "success_list" => [[
                    "model_id" => 0,
                    "original_price" => 11.11
                ]]
            ]
        ];
    }

    /**
     * 更新库存
     * @return void
     */
    public function updateStock()
    {
        $data = [
            "item_id" => 1000,
            "stock_list" => [
                [
                    "model_id" => 0,

                    "seller_stock" => [
                        [
                            "location_id" => "-",
                            "stock" => 0
                        ]
                    ]
                ]
            ]
        ];

        $this->shopApi('update_stock', '', $data);

        $return_data = [
            "error" => "-",
            "message" => "-",
            "warning" => "-",
            "request_id" => "-",
            "response" => [
                "failure_list" => [[
                    "model_id" => 0,
                    "failed_reason" => "-"
                ]],
                "success_list" => [[
                    "model_id" => 0,
                    "location_id" => "-",
                    "stock" => 0
                ]]
            ]
        ];
    }

}
